import Vue from 'vue';
import Router from 'vue-router';
import store from "@/store";

Vue.use(Router);
const router = new Router({
    mode: 'hash',
    base: process.env.BASE_URL,
    routes: [
        {
            path: '/404',
            name: 'notFound',
            component: () => import('@/views/public/404.vue'),
            meta: {
                title: '页面找不到',
                checkNetwork: false,
            }
        },
        {
            path: '/timeout',
            name: 'timeout',
            component: () => import('@/views/public/timeOut.vue'),
            meta: {
                title: '操作超时',
                checkNetwork: false,
            }
        },
        {
            path: '/networkError',
            name: 'networkError',
            component: () => import('@/views/public/networkError.vue'),
            meta: {
                title: '网络异常',
                checkNetwork: false,
            }
        },
        {
            path: '/notPage',
            name: 'notPage',
            component: () => import('@/views/public/notPage.vue'),
            meta: {
                title: '敬请期待',
                checkNetwork: false
            }
        },
        {
            path: '/update',
            name: 'update',
            component: () => import('@/views/public/update.vue'),
            meta: {
                title: '升级中',
                checkNetwork: false
            }
        },
        {
            path: '/',
            name: 'login',
            component: () => import('@/views/login/index.vue'),
            meta: {
                title: '登录'
            }
        },
        {
            path: '/layout',
            name: 'layout',
            component: () => import('@/views/layout/index.vue'),
            redirect: '/home' /* 重定向 */,
            children: [
                {
                    path: '/home',
                    name: 'home',
                    component: () => import(/* webpackChunkName: "layout" */'@/views/layout/home.vue'),
                    meta: {
                        title: '首页'
                    }
                },
                {
                    path: '/user',
                    name: 'user',
                    component: () => import(/* webpackChunkName: "layout" */'@/views/layout/user.vue'),
                    meta: {
                        title: '我的'
                    }
                },
                {
                    path: '/cart',
                    name: 'cart',
                    component: () => import(/* webpackChunkName: "layout" */'@/views/layout/cart.vue'),
                    meta: {
                        title: '购物车'
                    }
                },
                {
                    path: '/category',
                    name: 'category',
                    component: () => import(/* webpackChunkName: "layout" */'@/views/layout/category.vue'),
                    meta: {
                        title: '分类'
                    }
                }
            ]
        },
        {
            path: '/vantTreeSelect',
            name: 'vantTreeSelect',
            component: () => import(/* webpackChunkName: "pages" */'@/views/pages/vantTreeSelect.vue'),
            meta: {
                title: '树形图'
            }
        },
        {
            path: '/upload',
            name: 'upload',
            component: () => import(/* webpackChunkName: "pages" */'@/views/pages/upload.vue'),
            meta: {
                title: '文件上传'
            }
        },
        {
            path: '/fileType',
            name: 'fileType',
            component: () => import(/* webpackChunkName: "pages" */'@/views/pages/fileType.vue'),
            meta: {
                title: '文件格式展示'
            }
        },
    ]
});
router.beforeEach((to, from, next) => {
    store.dispatch('savePath', to)
    // console.log(to, from, next)
    // 数组实例方法includes，判断一个字符串是否包含在另一个字符串中，根据情况返回true或false。  path路径
    // 非权限页面直接放行
    next()
})
export default router
